package com.starbaba.log4j.view;

import java.io.IOException;
import java.util.List;

import com.base.common.log.LogService;
import com.opensymphony.xwork2.ModelDriven;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.log4j.model.Log4jCountBean;
import com.starbaba.log4j.service.Log4jStatisticsService;
import com.starbaba.log4j.service.impl.LogStatisticsServiceImpl;

/**
 * 错误日志数量统计Action
 * @author chenweijun
 *
 */
@SuppressWarnings({"deprecation","rawtypes","unchecked"})
public class LogListAction extends BaseAction implements ModelDriven<Log4jCountBean> {

	private static final long serialVersionUID = 1L;
	
	private Log4jCountBean model;
	private Log4jStatisticsService service; 
	
	public LogListAction(){
		service = new LogStatisticsServiceImpl();
	}

	@Override
	public Log4jCountBean getModel() {
		if(model == null){
			model = new Log4jCountBean();
		}
		return model;
	}
	
	/**
	 * 查询错误日志列表
	 */
	public void getLog4jList(){
		parsePageRequest();
		PageResponse pageResponse=new PageResponse();
		paramsMap=PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		List list=service.getLog4jList(paramsMap, pageRequest.getIDisplayStart(),pageRequest.getIDisplayLength());
		int count = service.getLog4jCount(paramsMap);
		try {
			pageResponse.setITotalDisplayRecords(count);
			pageResponse.setITotalRecords(count);
			pageResponse.setAaData(list);
			sendJsonMessage(JsonUtils.toJson(pageResponse, null, true, null, false));
		} catch(IOException e) {
			LogService.error(e);
		}
	}
	

}
